﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CMS.Models
{
    public class RecordProvider : IProvider<Record>
    {
        public CargoEntities db = new CargoEntities();

        public int Delete(Record t)
        {
            if (t == null) return 0;
            var model = db.Record.ToList().FirstOrDefault(item => item.Id == t.Id);
            if(model == null) return 0;
            db.Record.Remove(t);
            return db.SaveChanges();
        }

        public int Insert(Record t)
        {
            if(t == null) return 0;
            db.Record.Add(t);
            return db.SaveChanges();
        }

        public List<Record> Select()
        {
            return db.Record.ToList();
        }

        public int Update(Record t)
        {
            if (t == null) return 0;
            var model = db.Record.ToList().FirstOrDefault(item => item.Id == t.Id);
            if (model == null) return 0;
            model.Number = t.Number;
            return db.SaveChanges();
        }
    }
}
